#include "bsp.h"
#include <stdio.h>

void foo(int a) {
	int b;
	printf("process %d a = %d, b = %d\n", bsp_pid(), a, b);
	if (a == 0) {
		bsp_push_reg(&b, sizeof(int));
		bsp_push_reg(&a, sizeof(int));

	} else {
		bsp_push_reg(&a, sizeof(int));
		bsp_push_reg(&b, sizeof(int));
	}
	bsp_sync();
	bsp_get(1 - bsp_pid(), &a, 0, &a, sizeof(int));
	bsp_get(1 - bsp_pid(), &b, 0, &b, sizeof(int));
	bsp_sync();
	if (a == 0) {
		bsp_pop_reg(&b);
		bsp_pop_reg(&a);
	} else {
		bsp_pop_reg(&a);
		bsp_pop_reg(&b);
	}
	bsp_sync();
	printf("process %d a = %d, b = %d\n", bsp_pid(), a, b);
}

void main(int argc, char *argv[]) {
	bsp_begin(2);
	foo(bsp_pid());
	bsp_end();
}

